package fl.ass.service.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.page.Pager;
import cmm.service.core.framework.biz.BaseBizImpl;
import cmm.service.core.framework.dao.IBaseDao;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import fl.ass.facade.condition.AssDealCarCostQueryCondition;
import fl.ass.facade.constant.InterfaceConstants;
import fl.ass.facade.dto.AssDealCarCostDTO;
import fl.ass.service.dao.AssDealCarCostMapper;
import fl.ass.service.po.AssDealCarCost;
import fl.ass.service.service.IAssDealCarCostService;
import fl.ass.service.transform.AssDealCarCostTransform;

/**
 * @Description: 处置-转优车费用信息表 服务层接口实现
 * @Description: 类中已经实现了简单增删改查操作,可以直接使用,如果有需要重写该方法即可：
 * @Description: 1、add(TVO entity) 2、removeById(Long id) 3、modify(DTO entity) 4、selectById(Long id)	5、searchListPage(Pager page) 7、searchList(DTO dto)   
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class AssDealCarCostServiceImpl extends BaseBizImpl<AssDealCarCost, AssDealCarCostDTO, AssDealCarCostQueryCondition> implements IAssDealCarCostService {
	
	@SuppressWarnings("unused")
	private static final Logger logger = LoggerFactory.getLogger(IAssDealCarCostService.class);
	
	@Autowired
	private AssDealCarCostMapper assDealCarCostMapper;

	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;
	
	
	@Override
	public List<AssDealCarCostDTO> searchList(AssDealCarCostQueryCondition condition) throws BaseException {
		if(null == condition) return new ArrayList<AssDealCarCostDTO>();
		List<AssDealCarCost> list = this.assDealCarCostMapper.selectList(condition);
		return AssDealCarCostTransform.toDTOList(list);
	}
	
	@Override
	public IBaseDao<AssDealCarCost,AssDealCarCostQueryCondition> getDao() {
		return this.assDealCarCostMapper;
	}
	@Override
	public Pager findAssDealCarCostListByPage(Pager page) {
		List<AssDealCarCostDTO> list = this.assDealCarCostMapper.selectAssDealCarCostListPage(page);
		if(!CollectionUtils.isNotEmpty(list)){
			list = new ArrayList<AssDealCarCostDTO>();
		}
		SysDictionaryDTO dictionary = null;
		for(AssDealCarCostDTO dto : list){
			//处理费用项(ASS0015)
			if(StringUtils.isNotBlank(dto.getCostTypeCd())){
				dictionary = sysDictionaryApiService.getCode(InterfaceConstants.SYS_CODE, InterfaceConstants.ORG_CODE, InterfaceConstants.COST_TYPE_CD, dto.getCostTypeCd());
				if(null != dictionary){
					dto.setCostTypeCd(dictionary.getCodeNm());
				}
			}
		}
		page.setResultList(list);
		return page;
	}

	@Override
	public AssDealCarCostDTO selectAssDealCarCostById(Long id) {
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "主键不能为空");
		}
		return this.assDealCarCostMapper.selectAssDealCarCostById(id);
	}
}

